<?php

namespace app\index\validate;

use think\exception\ValidateException;
use think\Validate;

class Createvideo extends Validate
{
    protected $rule =   [
        'sale_id'  => 'require|integer',
        'title'   => 'require|chsAlphaNum|length:1,30',
        'width'   => 'require|integer|>=:720',
        'heigh'   => 'require|integer|>=:1280',
        'num'   => 'require|integer|between:1,20',
        'min'   => 'require|integer|>=:20|<:max',
        'max'   => 'require|integer|<=:30|>:min',
        'video'   => 'require|verJson',
    ];

    protected $field = [
        'sale_id'=>'活动',
        'title'=>'标题',
        'width'   => '视频宽度',
        'heigh'   => '视频高度',
        'num'   => '生成视频数量',
        'min'   => '视频最小时间',
        'max'   => '视频最大时间',
        'video'   => '素材',
    ];


    protected function verJson($value, $data){
        $video = json_encode($value);
        if(is_null($video)){
            return '素材内容格式不正确，请上传正确的json格式';
        }
        if(!isset($value['head'])) return '请上传视频片头素材！';
        if(empty($value['head'])) return '请至少上传一个视频片头素材！';
        if(!isset($value['tail'])) return '请上传视频片尾素材！';
        if(empty($value['tail'])) return '请至少上传一个视频片尾素材！';
        if(!isset($value['list'])) return '请上传视频正片素材！';
        if(empty($value['list'])) return '请至少上传一个视频正片素材！';
        return true;
    }
}